package com.ruoyi.iot.dataprocessing.strategy;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.PrimaryKeyIdUtils;
import com.ruoyi.iot.dataprocessing.domain.SensorMessage;
import com.ruoyi.iot.dataprocessing.enums.DataAssemblyEnum;

import java.util.Date;

public abstract class SensorMessageHandlerService {
    public abstract DataAssemblyEnum getDataAssemblyEnum();

    public SensorMessage messageHandle(byte[] payload) {
        JSONObject jsonObject = JSONObject.parseObject(new String(payload));
        SensorMessage sensorMessage = new SensorMessage();
        sensorMessage.setId(PrimaryKeyIdUtils.getSysIdWorker().nextId());
        sensorMessage.setDeviceType(jsonObject.getIntValue("type"));
        sensorMessage.setDeviceNo(jsonObject.getString("deviceId"));
        sensorMessage.setCustomerId(jsonObject.getLong("userId"));
        sensorMessage.setMessage(payload);
        sensorMessage.setTsStart(new Date(jsonObject.getLong("ts")));
        sensorMessage.setTsEnd(new Date(jsonObject.getLong("ts")));
        sensorMessage.setCreateTime(DateUtils.getNowDate());
        return sensorMessage;
    }

    public void push(Integer type,Long customerId,byte[] payload) {
    }
}
